<%@ tag language="java" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<%@ attribute name="id" type="java.lang.String" required="true" description="唯一标识"%>
<%@ attribute name="labelClass" type="java.lang.String" required="false" description="显示样式"%>
<%@ attribute name="labelName" type="java.lang.String" required="true" description="显示的文本"%>
<%@ attribute name="url" type="java.lang.String" required="true" description="相应Url"%>
<%@ attribute name="checkBoxName" type="java.lang.String" required="true" description="复选框名称"%>
<%@ attribute name="suburl" type="java.lang.String" required="true" description="提交的URL"%>

	<input id="url" value="${url}" type="hidden">
	<a id="${id}Button" href="javascript:void(0);" class="${labelClass}">${labelName}</a>
	<script type="text/javascript">


	$("#${id}Button").click(function(){
		if(!subFlag){
			loading('正在提交，请稍等...');
			return;
		}
		var checkedbox = $("input[name=${checkBoxName}]:checked");
    	if(checkedbox.length == 0){
    		showTip("请选择商品信息", "", 3000,0);
    		return;
    	}
		top.$.jBox.open("iframe:"+$("#url").val()+"${urlParam}", "选择门店", 700, $(top.document).height()-180, {
            buttons:{"确定":"ok","关闭":true}, submit:function(v, h, f){
                if (v=="ok"){
                	var contentWindow=h.find("iframe")[0].contentWindow;
                	var len= contentWindow.$("input[name^=storeList]").length;
                	var checks=contentWindow.$("input[name^=storeList]");
                	var idArray = new Array();
                	for(var i=0;i<len;i++){
                		if(checks[i].checked){
                			idArray.push(checks[i].value);
                		}
                	}
                	var checkedbox = $("input[name=${checkBoxName}]:checked");
                	var arrayId = "";
                	for(var i=0;i<checkedbox.length;i++){
                			if(i>0){
                				arrayId += ",";
                			}
                			arrayId += checkedbox[i].value;
                	}
                	$("#id").val(arrayId);
                	if(idArray.length>0){
                		$("#storeId").val(idArray);
                	}else{
                		$("#storeId").val("");
                	}
                	$("#storeForm").attr("action","${suburl}");
                	$("#storeForm").submit();
                	subFlag = false;
                }
            }, loaded:function(h){
                //全选
                var contentWindow=h.find("iframe")[0].contentWindow;
                var arrayAreaStore = contentWindow.$("input[name^=areaStore]");
                for(var i=0;i<arrayAreaStore.length;i++){
                	var index = $(arrayAreaStore[i]).attr("name").substring(10,11);
                	var arrayStoreList = contentWindow.$("input[name=storeList_"+index+"]");
                	var checkCount = 0;
                	for(var y=0;y<arrayStoreList.length;y++){
                		if(arrayStoreList[y].checked){
                			checkCount++;
                		}
                	}
                	if(arrayStoreList.length == checkCount){
                		arrayAreaStore[i].checked = true;
                	}
                }
                
            }
        });
	});
	
</script>
